package com.phenix.network.response

import com.phenix.network.base.Envelope
import retrofit2.Call
import retrofit2.CallAdapter
import java.lang.reflect.Type

class NetworkResponseAdapter<S : Any>(
    private val delegate: Type,
    private val failureHandler: NetworkResponseAdapterFactory.FailureHandler?,
    private val envelope: Envelope
) : CallAdapter<S, Call<NetworkResponse<S>>> {
    override fun responseType(): Type = delegate

    override fun adapt(call: Call<S>): Call<NetworkResponse<S>> {
        return NetworkResponseCall(call, failureHandler, envelope)
    }
}